<?php
session_start();
require 'authentication.php';
include('db_con.php');

    $file =  $_FILES["file"]["name"];
    $name = $_POST['name'];
    $price = $_POST['price'];
    $id = $_POST['id'];
    if($file != ''){
        $pic_name = $name.$file;
        
          move_uploaded_file($_FILES["file"]["tmp_name"],
          "pic/" . $pic_name);
          
            $query = "UPDATE `tractor` SET `name`='".$name."',`price`='".$price."',`pic_path`='".$pic_name."' WHERE tractor_id='".$id."'";
            $result = mysqli_query($db_con, $query);
            if($result){
                header("Location: index.php");
            }
    }else{
        $query = "UPDATE `tractor` SET `name`='".$name."',`price`='".$price."' WHERE tractor_id='".$id."'";
            $result = mysqli_query($db_con, $query);
            if($result){
                header("Location: index.php");
            }
    }
?>